package com.hxd.otc.module.fiat_deal.model;

import android.support.annotation.NonNull;

import com.hxd.otc.api.Constant;
import com.hxd.otc.api.IFiatDealApi;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.common.UserHelper;
import com.hxd.otc.module.fiat_deal.bean.DealRequestBean;
import com.hxd.otc.module.fiat_deal.bean.DealResultDataBean;
import com.hxd.otc.module.fiat_deal.bean.DealTeamBean;
import com.hxd.otc.module.order.bean.AllOrderBean;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.net.RetrofitManager;
import com.uber.autodispose.AutoDisposeConverter;

import java.util.ArrayList;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * 包  名 :  com.hxd.otc.module.deal.model
 * 类  名 :  DealModel
 * 作  者 :  胡庆岭
 * 时  间 :  2018/6/17 10:21
 * 描  述 :  ${交易model}
 */
public class DealModel {


    public void deal(@NonNull DealRequestBean bean, BaseObserver<AllOrderBean.DataBean> observer, AutoDisposeConverter<BaseBean<AllOrderBean.DataBean>> converter) {

        switch (bean.dealType) {
            case Constant.Deal.TYPE_BUY:
                RetrofitManager.getDefault().create(IFiatDealApi.class)
                        .dealBuy(bean.totalPrice, bean.orderId, bean.symbol,bean.detailPay)
                        .observeOn(AndroidSchedulers.mainThread())
                        .as(converter)
                        .subscribe(observer);
                break;
            case Constant.Deal.TYPE_SELL:

                RetrofitManager.getDefault().create(IFiatDealApi.class)
                        .dealSell(bean.totalPrice, bean.orderId, bean.symbol, bean.detailPay)
                        .observeOn(AndroidSchedulers.mainThread())
                        .as(converter)
                        .subscribe(observer);
                break;
        }


    }

    /**
     * @param supportCurrencyCode 虚拟币种
     * @param exType              // 买卖类型0买1卖
     * @param loginSource         写死otc
     * @param currentPage
     * @param showCount
     * @param observer
     * @param converter
     */

    public void getDealListData(String symbol, String supportCurrencyCode, String supportPay, int exType, String loginSource,
                                int currentPage, int showCount,
                                @NonNull BaseObserver<DealResultDataBean> observer,
                                @NonNull AutoDisposeConverter<BaseBean<DealResultDataBean>> converter) {

        RetrofitManager.getDefault().create(IFiatDealApi.class)
                .getDealListData(symbol, supportCurrencyCode, supportPay, exType, loginSource, currentPage, showCount)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    public void getCoinType(@NonNull BaseObserver<ArrayList<DealTeamBean>> observer,
                            @NonNull AutoDisposeConverter<BaseBean<ArrayList<DealTeamBean>>> converter) {

        RetrofitManager.getDefault().create(IFiatDealApi.class)
                .getCoinType("1")//0无感支付，1普通交易
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }
}
